<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
	<title>Editor example - Standalone collection editor</title>
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
	<link rel="stylesheet" type="text/css" href="../../css/editor.dataTables.min.css">
	<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="../resources/syntax/shCore.css">
	<link rel="stylesheet" type="text/css" href="../resources/demo.css">
	<style type="text/css" class="init">
	
	button.create,
	div.panel {
		position: relative;
		box-sizing: border-box;
		float: left;
		width: 23%;
		border: 1px solid #ccc;
		border-radius: 3px;
		background-color: #eee;
		min-height: 105px;
		padding: 5px;
		margin: 1em 2% 0 0;
	}

	button.create:hover {
		background-color: #ddd;
	}

	div.panel i.edit,
	div.panel i.remove {
		position: absolute;
		bottom: 5px;
		right: 5px;
		color: #999;
	}

	div.panel i.remove {
		right: 25px;
	}

	div.panel i.edit:hover,
	div.panel i.remove:hover {
		color: black;
	}

	div.panel dl {
		margin: 0;
	}

	div.panel dt {
		clear: both;
		float: left;
		width: 33%;
		padding-left: 2%;
		margin: 0;
		color: #999;
	}

	div.panel dd {
		float: left;
		width: 65%;
		margin: 0;
	}

	</style>
	<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.3.min.js">
	</script>
	<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js">
	</script>
	<script type="text/javascript" language="javascript" src="../../js/dataTables.editor.min.js">
	</script>
	<script type="text/javascript" language="javascript" src="../resources/syntax/shCore.js">
	</script>
	<script type="text/javascript" language="javascript" src="../resources/demo.js">
	</script>
	<script type="text/javascript" language="javascript" src="../resources/editor-demo.js">
	</script>
	<script type="text/javascript" language="javascript" class="init">
	


var editor; // use a global for the submit and return data rendering in the examples

// Template function to display the information panels. Editor will
// automatically keep the values up-to-date with any changes due to the use of
// the `data-editor-field` attribute. It knows which panel to update for each
// record through the use of `data-editor-id` in the container element.
function createPanel ( data )
{
	var id = data.DT_RowId;
	
	$(
		'<div class="panel" data-editor-id="'+id+'">'+
			'<i class="edit fa fa-pencil" data-id="'+id+'"/>'+
			'<i class="remove fa fa-times" data-id="'+id+'"/>'+
			'<dl>'+
				'<dt>Name:</dt>'+
				'<dd>'+
					'<span data-editor-field="first_name">'+data.first_name+'</span> '+
					'<span data-editor-field="last_name">'+data.last_name+'</span>'+
				'</dd>'+
				'<dt>Position:</dt>'+
				'<dd data-editor-field="position">'+data.position+'</dd>'+
				'<dt>Office:</dt>'+
				'<dd data-editor-field="office">'+data.office+'</dd>'+
			'</dl>'+
		'</div>'
	).appendTo( '#panels' );
}

$(document).ready(function() {
	editor = new $.fn.dataTable.Editor( {
		ajax: "../php/staff.php",
		fields: [ {
				label: "First name:",
				name: "first_name"
			}, {
				label: "Last name:",
				name: "last_name"
			}, {
				label: "Position:",
				name: "position"
			}, {
				label: "Office:",
				name: "office"
			}
		]
	} );

	// Create record - on create we insert a new panel
	editor.on( 'postCreate', function (e, json) {
		createPanel( json.data[0] );
	} );

	$('button.create').on( 'click', function () {
		editor
			.title('Create new record')
			.buttons('Create')
			.create();
	} );

	// Edit
	$('#panels').on( 'click', 'i.edit', function () {
		editor
			.title('Edit record')
			.buttons('Save changes')
			.edit( $(this).data('id') );
	} );

	// Remove
	$('#panels').on( 'click', 'i.remove', function () {
		editor
			.title('Delete record')
			.buttons('Delete')
			.message('Are you sure you wish to delete this record?')
			.remove( $(this).data('id') );
	} );

	// Load the initial data and display in panels
	$.ajax( {
		url: '../php/staff.php',
		dataType: 'json',
		success: function ( json ) {
			for ( var i=0, ien=json.data.length ; i<ien ; i++ ) {
				createPanel( json.data[i] );
			}
		}
	} );
} );



	</script>
</head>
<body class="dt-example">
	<div class="container">
		<section>
			<h1>Editor example <span>Standalone collection editor</span></h1>
			<div class="info">
				<p>While Editor is primarily used as an Editor for DataTables when considering multiple records, its standalone mode also supports the ability to edit individual
				items in a collection that have been displayed on the page without using DataTables. Consider the example below where data is read from the database about staff
				members and each record is shown in a <em>panel</em>. While DataTables could of course be use here, this approach adds the ability to show the data in ways that is
				not possible in a table.</p>
				<p>The key to this approach is that each panel uses the data attribute <code>data-editor-id</code> to specify the unique identifier that each panel belongs to. The
				<code>data-editor-field</code> attribute is then used for the elements in the panel to specify which field each element should represent.</p>
				<p>The <a href="//editor.datatables.net/reference/api/create()"><code class="api" title="Editor API method">create()</code></a>, <a href=
				"//editor.datatables.net/reference/api/edit()"><code class="api" title="Editor API method">edit()</code></a> and <a href=
				"//editor.datatables.net/reference/api/remove()"><code class="api" title="Editor API method">remove()</code></a> API methods are all used to provide full CRUD
				options for this collection editor.</p>
				<p>For additional information about using Editor without DataTables, please refer to the <a href="https://editor.datatables.net/manual/standalone">Editor
				standalone manual</a>.</p>
			</div>
			<div id="panels">
				<button class="create">New</button>
			</div>
			<div style="clear:both; padding-top: 2em;"></div>
			<ul class="tabs">
				<li class="active">Javascript</li>
				<li>HTML</li>
				<li>CSS</li>
				<li>Ajax</li>
				<li>Server-side script</li>
			</ul>
			<div class="tabs">
				<div class="js">
					<p>The Javascript shown below is used to initialise the table shown in this example:</p><code class="multiline language-js">var editor; // use a global for the submit and return data rendering in the examples

// Template function to display the information panels. Editor will
// automatically keep the values up-to-date with any changes due to the use of
// the `data-editor-field` attribute. It knows which panel to update for each
// record through the use of `data-editor-id` in the container element.
function createPanel ( data )
{
	var id = data.DT_RowId;
	
	$(
		'&lt;div class=&quot;panel&quot; data-editor-id=&quot;'+id+'&quot;&gt;'+
			'&lt;i class=&quot;edit fa fa-pencil&quot; data-id=&quot;'+id+'&quot;/&gt;'+
			'&lt;i class=&quot;remove fa fa-times&quot; data-id=&quot;'+id+'&quot;/&gt;'+
			'&lt;dl&gt;'+
				'&lt;dt&gt;Name:&lt;/dt&gt;'+
				'&lt;dd&gt;'+
					'&lt;span data-editor-field=&quot;first_name&quot;&gt;'+data.first_name+'&lt;/span&gt; '+
					'&lt;span data-editor-field=&quot;last_name&quot;&gt;'+data.last_name+'&lt;/span&gt;'+
				'&lt;/dd&gt;'+
				'&lt;dt&gt;Position:&lt;/dt&gt;'+
				'&lt;dd data-editor-field=&quot;position&quot;&gt;'+data.position+'&lt;/dd&gt;'+
				'&lt;dt&gt;Office:&lt;/dt&gt;'+
				'&lt;dd data-editor-field=&quot;office&quot;&gt;'+data.office+'&lt;/dd&gt;'+
			'&lt;/dl&gt;'+
		'&lt;/div&gt;'
	).appendTo( '#panels' );
}

$(document).ready(function() {
	editor = new $.fn.dataTable.Editor( {
		ajax: &quot;../php/staff.php&quot;,
		fields: [ {
				label: &quot;First name:&quot;,
				name: &quot;first_name&quot;
			}, {
				label: &quot;Last name:&quot;,
				name: &quot;last_name&quot;
			}, {
				label: &quot;Position:&quot;,
				name: &quot;position&quot;
			}, {
				label: &quot;Office:&quot;,
				name: &quot;office&quot;
			}
		]
	} );

	// Create record - on create we insert a new panel
	editor.on( 'postCreate', function (e, json) {
		createPanel( json.data[0] );
	} );

	$('button.create').on( 'click', function () {
		editor
			.title('Create new record')
			.buttons('Create')
			.create();
	} );

	// Edit
	$('#panels').on( 'click', 'i.edit', function () {
		editor
			.title('Edit record')
			.buttons('Save changes')
			.edit( $(this).data('id') );
	} );

	// Remove
	$('#panels').on( 'click', 'i.remove', function () {
		editor
			.title('Delete record')
			.buttons('Delete')
			.message('Are you sure you wish to delete this record?')
			.remove( $(this).data('id') );
	} );

	// Load the initial data and display in panels
	$.ajax( {
		url: '../php/staff.php',
		dataType: 'json',
		success: function ( json ) {
			for ( var i=0, ien=json.data.length ; i&lt;ien ; i++ ) {
				createPanel( json.data[i] );
			}
		}
	} );
} );</code>
					<p>In addition to the above code, the following Javascript library files are loaded for use in this example:</p>
					<ul>
						<li>
							<a href="//code.jquery.com/jquery-1.12.3.min.js">//code.jquery.com/jquery-1.12.3.min.js</a>
						</li>
						<li>
							<a href="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js">https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js</a>
						</li>
						<li>
							<a href="../../js/dataTables.editor.min.js">../../js/dataTables.editor.min.js</a>
						</li>
					</ul>
				</div>
				<div class="table">
					<p>The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:</p>
				</div>
				<div class="css">
					<div>
						<p>This example uses a little bit of additional CSS beyond what is loaded from the library files (below), in order to correctly display the table. The
						additional CSS used is shown below:</p><code class="multiline language-css">button.create,
	div.panel {
		position: relative;
		box-sizing: border-box;
		float: left;
		width: 23%;
		border: 1px solid #ccc;
		border-radius: 3px;
		background-color: #eee;
		min-height: 105px;
		padding: 5px;
		margin: 1em 2% 0 0;
	}

	button.create:hover {
		background-color: #ddd;
	}

	div.panel i.edit,
	div.panel i.remove {
		position: absolute;
		bottom: 5px;
		right: 5px;
		color: #999;
	}

	div.panel i.remove {
		right: 25px;
	}

	div.panel i.edit:hover,
	div.panel i.remove:hover {
		color: black;
	}

	div.panel dl {
		margin: 0;
	}

	div.panel dt {
		clear: both;
		float: left;
		width: 33%;
		padding-left: 2%;
		margin: 0;
		color: #999;
	}

	div.panel dd {
		float: left;
		width: 65%;
		margin: 0;
	}</code>
					</div>
					<p>The following CSS library files are loaded for use in this example to provide the styling of the table:</p>
					<ul>
						<li>
							<a href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css</a>
						</li>
						<li>
							<a href="../../css/editor.dataTables.min.css">../../css/editor.dataTables.min.css</a>
						</li>
						<li>
							<a href=
							"//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css</a>
						</li>
					</ul>
				</div>
				<div class="ajax">
					<p>This table loads data by Ajax. The latest data that has been loaded is shown below. This data will update automatically as any additional data is
					loaded.</p>
				</div>
				<div class="php">
					<p>The script used to perform the server-side processing for this table is shown below. Please note that this is just an example script using PHP. Server-side
					processing scripts can be written in any language, using <a href="//datatables.net/manual/server-side">the protocol described in the DataTables
					documentation</a>.</p>
				</div>
			</div>
		</section>
	</div>
	<section>
		<div class="footer">
			<div class="gradient"></div>
			<div class="liner">
				<h2>Other examples</h2>
				<div class="toc">
					<div class="toc-group">
						<h3><a href="../simple/index.html">Simple initialisation</a></h3>
						<ul class="toc">
							<li>
								<a href="../simple/simple.html">Basic initialisation</a>
							</li>
							<li>
								<a href="../simple/multiRow.html">Multi-row editing</a>
							</li>
							<li>
								<a href="../simple/fieldTypes.html">Field types</a>
							</li>
							<li>
								<a href="../simple/fieldDefaults.html">Setting defaults</a>
							</li>
							<li>
								<a href="../simple/i18n.html">Internationalisation</a>
							</li>
							<li>
								<a href="../simple/inTableControls.html">In table form controls</a>
							</li>
							<li>
								<a href="../simple/server-side-processing.html">Server-side processing</a>
							</li>
							<li>
								<a href="../simple/join.html">Join tables - working with multiple SQL tables</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../advanced/index.html">Advanced initialisation</a></h3>
						<ul class="toc">
							<li>
								<a href="../advanced/formOnlyData.html">Data shown only in the form</a>
							</li>
							<li>
								<a href="../advanced/tableOnlyData.html">Data shown in table only</a>
							</li>
							<li>
								<a href="../advanced/multiItem.html">Multi-item editing (rows, columns, cells)</a>
							</li>
							<li>
								<a href="../advanced/REST.html">REST interface</a>
							</li>
							<li>
								<a href="../advanced/deepObjects.html">Complex (nested) JSON data source</a>
							</li>
							<li>
								<a href="../advanced/localstorage.html">Ajax override - using localStorage for the data source</a>
							</li>
							<li>
								<a href="../advanced/jsonId.html">Row ID source specification</a>
							</li>
							<li>
								<a href="../advanced/htmlTable.html">DOM sourced table</a>
							</li>
							<li>
								<a href="../advanced/joinSelf.html">Join tables - self referencing join</a>
							</li>
							<li>
								<a href="../advanced/joinLinkTable.html">Join tables - link table</a>
							</li>
							<li>
								<a href="../advanced/joinArray.html">Join tables - one-to-many join</a>
							</li>
							<li>
								<a href="../advanced/upload.html">File upload</a>
							</li>
							<li>
								<a href="../advanced/upload-many.html">File upload (many)</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../extensions/index.html">DataTables extensions</a></h3>
						<ul class="toc">
							<li>
								<a href="../extensions/keyTable.html">Excel like keyboard navigation</a>
							</li>
							<li>
								<a href="../extensions/autoFill.html">Excel like AutoFill feature</a>
							</li>
							<li>
								<a href="../extensions/excel.html">AutoFill and KeyTable together</a>
							</li>
							<li>
								<a href="../extensions/exportButtons.html">Export buttons</a>
							</li>
							<li>
								<a href="../extensions/responsive.html">Responsive table extension</a>
							</li>
							<li>
								<a href="../extensions/rowReorder.html">Row reordering</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../dates/index.html">Dates and time</a></h3>
						<ul class="toc">
							<li>
								<a href="../dates/dates.html">Date picker</a>
							</li>
							<li>
								<a href="../dates/formatting.html">Formatted dates</a>
							</li>
							<li>
								<a href="../dates/datetime.html">Date and time input</a>
							</li>
							<li>
								<a href="../dates/time.html">Time inputs</a>
							</li>
							<li>
								<a href="../dates/time-increment.html">Time increment options</a>
							</li>
							<li>
								<a href="../dates/options-min-max.html">Options - min and max dates</a>
							</li>
							<li>
								<a href="../dates/options-week-numbers.html">Options - week numbers</a>
							</li>
							<li>
								<a href="../dates/options-disable-days.html">Options - disable days</a>
							</li>
							<li>
								<a href="../dates/i18n.html">Internationalisation</a>
							</li>
							<li>
								<a href="../dates/jqueryui.html">jQuery UI DatePicker</a>
							</li>
							<li>
								<a href="../dates/jqueryui-formatting.html">jQuery UI DatePicker with custom formatting</a>
							</li>
							<li>
								<a href="../dates/html5.html">HTML5 date input</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../inline-editing/index.html">Inline editing</a></h3>
						<ul class="toc">
							<li>
								<a href="../inline-editing/simple.html">Simple inline editing</a>
							</li>
							<li>
								<a href="../inline-editing/tabControl.html">Tab between columns</a>
							</li>
							<li>
								<a href="../inline-editing/options.html">Editing options - submit on blur</a>
							</li>
							<li>
								<a href="../inline-editing/submitData.html">Editing options - submit full row data</a>
							</li>
							<li>
								<a href="../inline-editing/submitButton.html">Inline editing with a submit button</a>
							</li>
							<li>
								<a href="../inline-editing/editIcon.html">Edit icon</a>
							</li>
							<li>
								<a href="../inline-editing/join.html">Joined tables</a>
							</li>
							<li>
								<a href="../inline-editing/columns.html">Selected columns only</a>
							</li>
							<li>
								<a href="../inline-editing/responsive.html">Responsive integration</a>
							</li>
							<li>
								<a href="../inline-editing/fixedcolumns.html">FixedColumns integration</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../bubble-editing/index.html">Bubble editing</a></h3>
						<ul class="toc">
							<li>
								<a href="../bubble-editing/simple.html">Simple bubble editing</a>
							</li>
							<li>
								<a href="../bubble-editing/grouped.html">Multiple fields in a bubble</a>
							</li>
							<li>
								<a href="../bubble-editing/options.html">Form control and display options</a>
							</li>
							<li>
								<a href="../bubble-editing/defaultOptions.html">Default control and display options</a>
							</li>
							<li>
								<a href="../bubble-editing/inTableControls.html">Bubble editing with in table row controls</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../api/index.html">API</a></h3>
						<ul class="toc">
							<li>
								<a href="../api/confirmClose.html">Events - unsaved changes close confirmation</a>
							</li>
							<li>
								<a href="../api/dependentFields.html">Dependent fields</a>
							</li>
							<li>
								<a href="../api/clientValidation.html">Client-side validation</a>
							</li>
							<li>
								<a href="../api/triggerButton.html">Customised control buttons</a>
							</li>
							<li>
								<a href="../api/backNext.html">Previous / next editing buttons</a>
							</li>
							<li>
								<a href="../api/cancelButton.html">Cancel button</a>
							</li>
							<li>
								<a href="../api/checkbox.html">Always shown checkbox</a>
							</li>
							<li>
								<a href="../api/duplicateButton.html">Duplicate button</a>
							</li>
							<li>
								<a href="../api/removeMessage.html">Custom delete / remove message</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="./index.html">Standalone</a></h3>
						<ul class="toc active">
							<li>
								<a href="./simple.html">Simple standalone editing</a>
							</li>
							<li>
								<a href="./bubble.html">Bubble editing</a>
							</li>
							<li>
								<a href="./inline.html">Inline editing</a>
							</li>
							<li class="active">
								<a href="./collection.html">Standalone collection editor</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../styling/index.html">Styling</a></h3>
						<ul class="toc">
							<li>
								<a href="../styling/bootstrap.html">Bootstrap</a>
							</li>
							<li>
								<a href="../styling/foundation.html">Foundation</a>
							</li>
							<li>
								<a href="../styling/jqueryui.html">jQuery UI</a>
							</li>
							<li>
								<a href="../styling/fieldDisplay.html">Field display styling options</a>
							</li>
							<li>
								<a href="../styling/columns.html">Multi-column layout</a>
							</li>
							<li>
								<a href="../styling/large.html">Large window layout</a>
							</li>
							<li>
								<a href="../styling/stackedInputs.html">Stacked inputs</a>
							</li>
							<li>
								<a href="../styling/envelope.html">Envelope display controller</a>
							</li>
							<li>
								<a href="../styling/envelopeInTable.html">Envelope display with in table controls</a>
							</li>
						</ul>
					</div>
					<div class="toc-group">
						<h3><a href="../plug-ins/index.html">Plug-ins</a></h3>
						<ul class="toc">
							<li>
								<a href="../plug-ins/fieldPlugin.html">Custom field type plug-ins</a>
							</li>
							<li>
								<a href="../plug-ins/displayController.html">Custom display controller</a>
							</li>
						</ul>
					</div>
				</div>
				<div class="epilogue">
					<p>Please refer to the <a href="http://www.datatables.net">DataTables documentation</a> for full information about its API properties and methods.<br>
					Additionally, there are a wide range of <a href="http://www.datatables.net/extensions">extensions</a> and <a href=
					"http://www.datatables.net/plug-ins">plug-ins</a> which extend the capabilities of DataTables.</p>
					<p class="copyright">DataTables designed and created by <a href="http://www.sprymedia.co.uk">SpryMedia Ltd</a> © 2007-2016<br>
					DataTables is licensed under the <a href="http://www.datatables.net/mit">MIT license</a>.</p>
				</div>
			</div>
		</div>
	</section>
</body>
</html>